<?php
// The source code packaged with this file is Free Software, Copyright (C) 2005 by
// Ricardo Galli <gallir at uib dot es>.
// It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
// You can get copies of the licenses here:
// 		http://www.affero.org/oagpl.html
// AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING".
include_once('Smarty.class.php');
$main_smarty = new Smarty;

include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'ts.php');
include(mnminclude.'link.php');
include(mnminclude.'tags.php');
include(mnminclude.'user.php');
include(mnminclude.'smartyvariables.php');
include(mnminclude.'csrf.php');

// require user to log in
force_authentication();

// restrict access to god and admin only
$amIgod = checklevel('god');
msset('amIgod', $amIgod);

$canIhaveAccess = checklevel('god') || checklevel('admin');
if (! $canIhaveAccess) {
    msset('tpl_center', $the_template . '/admin_templates/admin_access_denied');
    $main_smarty->display($the_template . '/pligg.tpl');
    die;
}

$main_smarty = do_sidebar($main_smarty);

define('pagename', 'admin_users');
msset('pagename', pagename);

$csrf = new csrf();

$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';

if ($mode == "newuser") {
    $username = $db->escape(trim($_POST['username']));
    $password = $db->escape(trim($_POST['password']));
    $email = $db->escape(trim($_POST['email']));
    $level = $db->escape(trim($_POST['level']));
    $saltedpass = generateHash($password);
    if (! isset($username) || strlen($username) < 3) {
        msset(usererror, msconf('PLIGG_Visual_Register_Error_UserTooShort'));
    }
    elseif (! preg_match('/^[a-zA-Z0-9\-\.@]+$/', $username)) {
        msset(usererror, msconf('PLIGG_Visual_Register_Error_UserInvalid'));
    }
    elseif (user_exists($username)) {
        msset(usererror, msconf('PLIGG_Visual_Register_Error_UserExists'));
    }
    elseif (! check_email($email)) {
        msset(usererror, msconf('PLIGG_Visual_Register_Error_BadEmail'));
    }
    elseif (email_exists($email)) {
        msset(usererror, msconf('PLIGG_Visual_Register_Error_EmailExists'));
    }
    elseif (strlen($password) < 5) {
        msset(usererror, msconf('PLIGG_Visual_Register_Error_FiveCharPass'));
    }
    else {
        $db->query(
            "INSERT INTO " . table_users
            . " (user_login, user_level, user_email, user_pass, user_date)"
            . " VALUES ('$username', '$level', '$email', '$saltedpass', now())");
        header("Location: admin_users.php");
        die;
    }
}

if ($mode == "view") {
    $csrf->create('admin_users_resetpass', true, true);
    $csrf->create('admin_users_promote', true, true);

    $userdata = userdataAssign($main_smarty, $_GET['user']);

    $level = $userdata[0]['user_level'];

    if ($level == 'newbie') {
        msset('promoteLink', promoteLink('normal', 'change to normal'));

    } else if ($level == 'normal' || $level == 'disabled') {
        msset('promoteLink', promoteLink('newbie', 'change to newbie'));
    }

    setnav('PLIGG_Visual_Breadcrumb_View_User');

    // module system hook
    $vars = '';
    check_actions('admin_users_view', $vars);

    // show the template
    msset('tpl_center', $the_template . '/admin_templates/user_show_center');
    $main_smarty->display($the_template . '/pligg.tpl');
    die;
}

if ($mode == "promote") {
    $csrf->check_expired('admin_users_promote');
    if (! $csrf->check_valid($_GET['token'], 'admin_users_promote')) {
        $csrf->show_invalid_error(1);
        die;
    }

    $user = new User();
    $user->username = trim($_GET['user']);
    if (! $user->read()) {
        showmyerror('userdoesntexist');
    }

    $level = trim($_GET['level']);
    $ok = ($user->level == 'normal' && $level == 'newbie');
    $ok = $ok || ($user->level == 'disabled' && $level == 'newbie');
    $ok = $ok || ($user->level == 'newbie' && $level == 'normal');
    if (! $ok) {
        echo "can't change level from {$user->level} to {$level}";
        die;
    }

    $user->level = $level;
    $user->store();

    header("Location: ".my_pligg_base
           ."/admin_users.php?mode=view&user={$user->username}");
    die;
}

if ($mode == "edit") {
    $csrf->create('admin_users_edit', true, true);

    $userdata = userdataAssign($main_smarty, $_GET['user']);

    canIChangeUser($userdata[0]['user_level'], $userdata[0]['user_login']);

    msset('levels', array('normal','god','admin','newbie','disabled'));

    setnav('PLIGG_Visual_Breadcrumb_Edit_User');

    // module system hook
    $vars = '';
    check_actions('admin_users_edit', $vars);

    // show the template
    msset('tpl_center', $the_template . '/admin_templates/user_edit_center');
    $main_smarty->display($the_template . '/pligg.tpl');
    die;
}

if ($mode == 'editsave') {
    $csrf->check_expired('admin_users_edit');
    if (! $csrf->check_valid($_GET['token'], 'admin_users_edit')) {
        $csrf->show_invalid_error(1);
        die;
    }

    $user = $db->get_row(
        'SELECT * FROM ' . table_users
        .' WHERE user_login="'.$db->escape($_GET["user"]).'"');

    if (! $user) {
        showmyerror('userdoesntexist');
        die;
    }

    canIChangeUser($user->user_level, $user->user_login);

    $userdata = new User();
    $userdata->username = $user->user_login;
    if(!$userdata->read()) {
        echo "Error reading user data.";
        die;
    }

    // module system hook
    $vars = '';
    check_actions('admin_users_save', $vars);

    $userdata->username = trim($_GET["login"]);
    $userdata->level = trim($_GET["level"]);
    $userdata->email = trim($_GET["email"]);
    $userdata->store();

    setnav('PLIGG_Visual_Breadcrumb_Edit_User_Data_Saved');

    header("Location: ".my_pligg_base."/admin_users.php?mode=view&user=".$_GET["login"]."");
    die;
}

if ($mode == "resetpass") {
    $csrf->check_expired('admin_users_resetpass');
    if (! $csrf->check_valid($_GET['token'], 'admin_users_resetpass')) {
        $csrf->show_invalid_error(1);
        die;
    }

    $user = $db->get_row(
        'SELECT * FROM ' . table_users
        .' WHERE user_login="'.$db->escape($_GET["user"]).'"');

    if (! $user) {
        showmyerror('userdoesntexist');
        die;
    }

    canIChangeUser($user->user_level, $user->user_login);

    $newPassword = substr(sha1(mt_rand()), 0, 12);
    $hashedPassword = generateHash($newPassword);

    $db->query(
        'UPDATE `' . table_users . '`'
        ." SET `user_pass` = '{$hashedPassword}'"
        .' WHERE `user_login` = "'.$db->escape($_GET["user"]).'"');

    setnav('PLIGG_Visual_Breadcrumb_User_Reset_Pass');

    msset('newPassword', $newPassword);

    // show the template
    msset('tpl_center', $the_template . '/admin_templates/user_password_reset_center');
    $main_smarty->display($the_template . '/pligg.tpl');
    die;
}

if ($mode == "disable") {
    $csrf->create('admin_users_disable', true, true);
    $csrf->create('admin_users_resetpass', true, true);

    if ($_GET["user"] == "god"){
        echo "You can't disable this user";
        die;
    }

    $userdata = userdataAssign($main_smarty, $_GET['user']);

    if (! $userdata) {
        showmyerror('userdoesntexist');
        die;
    }

    $user = $userdata[0];

    canIChangeUser($user['user_level'], $user['user_login']);

    setnav('PLIGG_Visual_Breadcrumb_User_Disable');

    msset('user', $user['user_login']);

    // show the template
    msset('tpl_center', $the_template . '/admin_templates/user_disable_step1_center');
    $main_smarty->display($the_template . '/pligg.tpl');
    die;
}

if ($mode == "yesdisable") {
    $csrf->check_expired('admin_users_disable');

    if (! $csrf->check_valid($_GET['token'], 'admin_users_disable')) {
        $csrf->show_invalid_error(2);
        die;
    }

    $user = $db->get_row(
        'SELECT * FROM ' . table_users
        .' WHERE user_login="'.$db->escape($_GET['user']).'"');

    if (! $user) {
        showmyerror('userdoesntexist');
    }

    canIChangeUser($user->user_level, $user->user_login);

    $db->query(
        'UPDATE `' . table_users . '`'
        .' SET `user_pass` = "-disabled-"'
        .' WHERE `user_login` = "'.$db->escape($user->user_login).'"');
    $db->query(
        'UPDATE `' . table_users . '`'
        .' SET `user_level` = "disabled"'
        .' WHERE `user_login` = "'.$db->escape($user->user_login).'"');

    header("Location: ".my_pligg_base
           ."/admin_users.php?mode=view&user="
           .urlencode($user->user_login));
    die;
}

if ($mode == "killspam") {
    $csrf->create('admin_users_killspam', true, true);
    $csrf->create('admin_users_resetpass', true, true);

    if ($_GET['user'] == "god") {
        echo "You can't killspam this user";
        die;
    }

    $user = $db->get_row(
        'SELECT * FROM ' . table_users
        .' where user_login="'.$db->escape($_GET['user']).'"');

    if (! $user) {
        showmyerror('userdoesntexist');
        die;
    }

    userdataAssign($main_smarty, $_GET['user']);

    canIChangeUser($user->user_level, $user->user_login);

    setnav('PLIGG_Visual_Breadcrumb_User_Killspam');

    msset('user', $user->user_login);
    // show the template
    msset('tpl_center',
          $the_template . '/admin_templates/user_killspam_step1_center');
    $main_smarty->display($the_template . '/pligg.tpl');
    die;
 }

if ($mode == "yeskillspam") {
    $csrf->check_expired('admin_users_killspam');
    if (! $csrf->check_valid($_GET['token'], 'admin_users_killspam')) {
        $csrf->show_invalid_error(1);
        die;
    }

    if ($_GET['user'] == "god") {
        echo "You can't killspam this user";
        die;
    }

    $user = $db->get_row(
        'SELECT * FROM ' . table_users
        .' where user_login="'.$db->escape($_GET['user']).'"');

    if (! $user) {
        showmyerror('userdoesntexist');
        die;
    }

    canIChangeUser($user->user_level, $user->user_login);

    $db->query(
        'UPDATE `' . table_users . '`'
        .' SET `user_pass` = "-disabled-"'
        .' WHERE `user_login` = "'.$db->escape($user->user_login).'"');
    $db->query(
        'UPDATE `' . table_users . '`'
        .' SET `user_level` = "disabled"'
        .' WHERE `user_login` = "'.$db->escape($user->user_login).'"');

    $db->query(
        'UPDATE `' . table_links . '`'
        .' SET `link_status` = "discard"'
        .' WHERE `link_author` = "'.$db->escape($user->user_id).'"');
    $db->query(
        'DELETE FROM `' . table_comments . '`'
        .' WHERE `comment_user_id` = "'.$db->escape($user->user_id).'"');

    setnav('PLIGG_Visual_Breadcrumb_User_Disable_2');

    header("Location: ".my_pligg_base."/admin_users.php?mode=view&user="
           .urlencode($user->user_login));
    die;
 }

if ($mode == "viewlinks") {
    $offset = (get_current_page() - 1)*25;

    $userdata = userdataAssign($main_smarty, $_GET['user']);
    $usersql = mysql_query(
        "SELECT * FROM " . table_users
        ." WHERE user_login='".$db->escape($_GET['user'])."'");
    $userdata = array();
    while ($row = mysql_fetch_array ($usersql, MYSQL_ASSOC)) array_push ($userdata, $row);
    msset('userdata', $userdata);

    msset('user', $userdata[0]['user_login']);

    if(isset($_POST["process"])) {
        $qUserid = $db->escape($userdata[0]['user_id']);
        switch ($_REQUEST["filter"]) {
        case 'Published':
            $filtered = mysql_query(
                "SELECT * FROM " . table_links
                ." WHERE link_author='".$qUserid."'"
                ." AND link_status = 'published' ORDER BY link_date DESC");
            break;
        case 'Upcoming':
            $filtered = mysql_query(
                "SELECT * FROM " . table_links
                ." WHERE link_author='".$qUserid."'"
                ." AND link_status = 'queued' ORDER BY link_date DESC");
            break;
        case 'Discard':
            $filtered = mysql_query(
                "SELECT * FROM " . table_links
                ." WHERE link_author='".$qUserid."'"
                ." AND link_status = 'discard' ORDER BY link_date DESC");
            break;
        case 'All':
            $filtered = mysql_query(
                "SELECT * FROM " . table_links
                ." WHERE link_author='".$qUserid."'"
                ." ORDER BY link_date DESC LIMIT $offset,25");
            $rows = $db->get_var(
                "SELECT count(*) FROM " . table_links
                ." WHERE link_author='".$qUserid."'");
            break;
        case 'Search':
            $qKeyword = $db->escape($_POST['keyword']);
            $filtered = mysql_query(
                "SELECT * FROM " . table_links
                ." WHERE link_author='".$qUserid."'"
                ." AND link_title LIKE '%".$qKeyword."%'"
                ." OR link_content LIKE '%".$qKeyword."%'"
                ." ORDER BY link_date DESC");
            break;
        }
    }
    else {
        $filtered = mysql_query(
            "SELECT * FROM " . table_links
            ." WHERE link_author='".$db->escape($userdata[0]['user_id'])."'"
            ." ORDER BY link_date DESC LIMIT $offset,25");
        $rows = $db->get_var(
            "SELECT count(*) FROM " . table_links
            ." WHERE link_author='".$db->escape($userdata[0]['user_id'])."'");
    }
    $links = array();
    while ($row = mysql_fetch_array ($filtered, MYSQL_ASSOC)) {
		if (empty($row['link_title'])) {
			$row['link_title'] = "(none)";
		}
        array_push ($links, $row);
    }
    msset('links', $links);

    // breadcrumbs and page title
    $navwhere['text1'] = msconf('PLIGG_Visual_Header_AdminPanel');
    $navwhere['link1'] = getmyurl('admin', '');
    $navwhere['text2'] = msconf('PLIGG_Visual_Header_AdminPanel_1');
    $navwhere['link2'] = my_pligg_base . "/admin_users.php";
    $navwhere['text3'] = $_GET["user"];
    $navwhere['link3'] = my_pligg_base."/admin_users.php?mode=view&user=".$_GET['user']."";
    $navwhere['text4'] = msconf('PLIGG_Visual_View_User_Sub_Links');
    msset('navbar_where', $navwhere);
    msset('posttitle', " / " . msconf('PLIGG_Visual_Header_AdminPanel'));

    // if admin changes the link status
    if (isset($_GET['action']) && $_GET['action'] == "bulkmod") {
        if(isset($_POST['submit'])) {
            $comment = array();
            foreach ($_POST["link"] as $k => $v) {
                $comment[intval($k)] = $v;
            }
            foreach($comment as $key => $value) {
                $qKey = $db->escape($key);
                $qValue = $db->escape($value);
                switch ($value) {
                case 'publish':
                case 'queued':
                case 'discard':
                    $db->query(
                        'UPDATE `' . table_links . '`'
                        .' SET `link_status` = "'.$qValue.'"'
                        .' WHERE `link_id` = "'.$qKey.'"');
                }
            }

            header("Location: ".my_pligg_base."/admin_users.php?mode=viewlinks&user=".$_POST['user']."");
            die;
        }
    }

    // show the template
    msset('tpl_center', $the_template . '/admin_templates/user_view_links_center');
    $main_smarty->display($the_template . '/pligg.tpl');
    die;
 }

if ($mode == "viewcomments") {
    $offset = (get_current_page() - 1)*25;

    $userdata = userdataAssign($main_smarty, $_GET['user']);
    msset('user', $userdata[0]['user_login']);

    $qUserId = $db->escape($userdata[0]['user_id']);
    if (isset($_REQUEST['action']) && $_REQUEST['action'] == "search") {
        $qKeyword = $db->escape($_REQUEST['keyword']);
        $usersql = mysql_query(
            "SELECT * FROM " . table_comments
            ." WHERE comment_user_id='".$qUserId."'"
            ." AND comment_content LIKE '%".$qKeyword."%'"
            ." ORDER BY comment_id DESC LIMIT $offset,25");
    } else {
        $usersql = mysql_query(
            "SELECT * FROM " . table_comments
            ." WHERE comment_user_id='".$qUserId."'"
            ." ORDER BY comment_id DESC LIMIT $offset,25");
    }

    $comments = array();
    while ($row = mysql_fetch_array ($usersql, MYSQL_ASSOC)) {
        array_push ($comments, $row);
    }
    msset('comments', $comments);

    $rows = $db->get_var(
        "SELECT count(*) FROM " . table_comments
        ." WHERE comment_user_id='".$qUserId."'");

    // breadcrumbs and page title
    $navwhere['text1'] = msconf('PLIGG_Visual_Header_AdminPanel');
    $navwhere['link1'] = getmyurl('admin', '');
    $navwhere['text2'] = msconf('PLIGG_Visual_Header_AdminPanel_1');
    $navwhere['link2'] = my_pligg_base . "/admin_users.php";
    $navwhere['text3'] = $_GET["user"];;
    $navwhere['link3'] = my_pligg_base."/admin_users.php?mode=view&user=".$_GET['user']."";
    $navwhere['text4'] = msconf('PLIGG_Visual_Breadcrumb_View_Comments');
    msset('navbar_where', $navwhere);
    msset('posttitle', " / " . msconf('PLIGG_Visual_Header_AdminPanel'));

    // if admin deletes comment
    if (isset($_GET['action']) && $_GET['action'] == "bulkmod") {
        if (isset($_POST['submit'])) {
            $comment = array();
            foreach ($_POST["comment"] as $k => $v) {
                $comment[intval($k)] = $v;
            }
            foreach($comment as $key => $value) {
                $qKey = $db->escape($key);
                if ($value == "discard") {
                    $db->query(
                        'DELETE FROM `' . table_comments . '`'
                        .' WHERE `comment_id` = "'.$qKey.'"');
                    $db->query(
                        'DELETE FROM `' . table_comments . '`'
                        .' WHERE `comment_parent` = "'.$qKey.'"');
                }
            }

            header("Location: ".my_pligg_base."/admin_users.php?mode=viewcomments&user=".$_POST['user']."");
            die;
        }
    }

    // show the template
    msset('tpl_center', $the_template . '/admin_templates/user_view_comments_center');
    $main_smarty->display($the_template . '/pligg.tpl');
    die;
}

if ($mode == "search") {
    $usersperpage = 50;
    $offset = (get_current_page() - 1)*$usersperpage;
    $qKeyword = $db->escape($_GET['keyword']);

    $orderby = 'ORDER BY user_lastlogin DESC';

    $rows = $db->get_var(
        "SELECT count(*) FROM " . table_users
        ." WHERE user_login LIKE '%".$qKeyword."%'"
        ." OR user_level LIKE '%".$qKeyword."%'"
        ." OR user_email LIKE '%".$qKeyword."%'"
        ." OR user_date LIKE '%".$qKeyword."%'");

    $searchsql = mysql_query(
        "SELECT * FROM " . table_users
        ." WHERE user_login LIKE '%".$qKeyword."%'"
        ." OR user_level LIKE '%".$qKeyword."%'"
        ." OR user_email LIKE '%".$qKeyword."%'"
        ." OR user_date LIKE '%".$qKeyword."%'"
        ." {$orderby}"
        ." LIMIT $offset,$usersperpage");

    $userlist = array();
    while ($row = mysql_fetch_array ($searchsql, MYSQL_ASSOC)) {
        array_push ($userlist, $row);
    }
    foreach ($userlist as $key => $val) {
        $userlist[$key]['Avatar'] =
            get_avatar('large', "", $val['user_login'], $val['user_email']);
    }
    msset('userlist', $userlist);

    $keyword = htmlspecialchars($_GET['keyword']);

    setnav(msconf('PLIGG_Visual_Breadcrumb_Search') . $keyword);

    // show the template
    msset('tpl_center', $the_template . '/admin_templates/user_listall_center');
    $main_smarty->display($the_template . '/pligg.tpl');
    die;
}

// No options are selected, so show the list of users.
$offset = (get_current_page() - 1)*$top_users_size;
$rows = $db->get_var("SELECT count(*) FROM " .table_users."");

$users = mysql_query(
    "SELECT * FROM " . table_users
    ." ORDER BY `user_date` LIMIT $offset,$top_users_size");

$userlist = array();
while ($row = mysql_fetch_array ($users, MYSQL_ASSOC)) {
    array_push ($userlist, $row);
}
foreach ($userlist as $key => $val){
    $userlist[$key]['Avatar'] =
        get_avatar('large', "", $val['user_login'], $val['user_email']);
}

msset('userlist', $userlist);

setnav();

// show the template
msset('tpl_center', $the_template . '/admin_templates/user_listall_center');
$main_smarty->display($the_template . '/pligg.tpl');
die;

//----------------

function canIChangeUser($user_level, $target) {
    global $amIgod, $main_smarty;

    //Don't want to let admins reset other admins or god
    $viewer = $main_smarty->get_template_vars('user_logged_in');

    if ($viewer != $target
        && !$amIgod
        && (($user_level == 'god') || ($user_level == 'admin')))
    {
        echo "Access denied";
        die;
    }
}

function showmyerror()
{
    global $main_smarty, $the_template;
    msset('user', $_GET["user"]);

    // breadcrumbs and page title
    $navwhere['text1'] = msconf('PLIGG_Visual_Header_AdminPanel');
    $navwhere['link1'] = getmyurl('admin', '');
    $navwhere['text2'] = msconf('PLIGG_Visual_Header_AdminPanel_1');
    $navwhere['link2'] = my_pligg_base . "/admin_users.php";
    $navwhere['text3'] = msconf('PLIGG_Visual_Breadcrumb_User_Does_Not_Exist');
    msset('navbar_where', $navwhere);
    msset('posttitle', " / " . msconf('PLIGG_Visual_Header_AdminPanel'));

    // show the template
    msset('tpl_center', $the_template . '/admin_templates/user_doesnt_exist_center');
    $main_smarty->display($the_template . '/pligg.tpl');
    die;
}

function userdataAssign($smarty, $user) {
    global $db;

    $query = mysql_query(
        'SELECT * FROM ' . table_users
        .' WHERE user_login="'.$db->escape($user).'"');

    $userdata = array();
    while ($rows = mysql_fetch_array($query, MYSQL_ASSOC)) {
        $userdata[] = $rows;
    }

    foreach ($userdata as $k => $v) {
        $userdata[$k]['Avatar'] =
            get_avatar('large', "", $v['user_login'], $v['user_email']);
    }

    $smarty->assign('userdata', $userdata);

    $linkcount = 0;
    $commentcount = 0;
    $votecount = 0;

    if ($userdata) {
        $user_id = $userdata[0]['user_id'];
        $q_user_id = $db->escape($user_id);
        $linkcount = $db->get_var(
            'SELECT count(*) FROM ' . table_links
            ." WHERE link_author='{$q_user_id}'");
        $commentcount = $db->get_var(
            'SELECT count(*) FROM ' . table_comments
            ." WHERE comment_user_id='{$q_user_id}'");
        $votecount = $db->get_var(
            'SELECT count(*) FROM ' . table_votes
            ." WHERE vote_user_id='{$q_user_id}'");
    }

    $smarty->assign('linkcount', $linkcount);
    $smarty->assign('commentcount', $commentcount);
    $smarty->assign('votecount', $votecount);

    return $userdata;
}

function promoteLink($level, $label) {
    global $csrf;
    $token = $csrf->get_value('admin_users_promote');
    return "<a class='promoteLink' href='"
        ."admin_users.php"
        ."?mode=promote"
        ."&user={$_GET['user']}"
        ."&level={$level}"
        ."&token={$token}"
        ."'>[{$label}]</a>";
}

function msconf($varname) {
    global $main_smarty;
    return $main_smarty->get_config_vars($varname);
}

function msset($var, $value) {
    global $main_smarty;
    $main_smarty->assign($var, $value);
}

function maybe_msconf($str) {
    $value = msconf($str);
    return  (empty($value) ? $str : $value);
}

function setnav($text3='') {
    $nav['text1'] = msconf('PLIGG_Visual_Header_AdminPanel');
    $nav['link1'] = getmyurl('admin', '');

    $nav['text2'] = msconf('PLIGG_Visual_Header_AdminPanel_1');
    $nav['link2'] = my_pligg_base . "/admin_users.php";

    $nav['link3'] = '';
    if (!empty($text3)) {
        $nav['text3'] = maybe_msconf($text3);
    }

    $nav['link4'] = '';
    $nav['text4'] = '';

    msset('navbar_where', $nav);

    msset('posttitle', " / " . msconf('PLIGG_Visual_Header_AdminPanel'));
}

function fnShortDate($date) {
    $words = explode(' ', $date);
    return $words[0];
}
